<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.biz.conf.Global"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jqGird</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <style>
        .ml10 {
            margin-left: 15px;
        }
        .wddd-list-jtzl {
            padding: 10px 0 0 !important;
            text-align: center;
        }.wddd-list-jtzl>ul>li {
             float: left;
             cursor: pointer;
         }
        ul,li{
            list-style-type: none;
        }

    </style>

</head>

<body class="gray-bg" >
<div class="wrapper wrapper-content  animated fadeInRight" id="ccbb">
    <div class="row">
        <div class="col-sm-12">
            <div class="row">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>搜索条件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-2" style="display: none;"><input placeholder="用户名" id="personName" class="form-control" ></div>
                            <div class="col-md-2" ><input placeholder="手机号" id="phone" class="form-control" ></div>
                            <div class="col-md-2"><input placeholder="开始日期" id="search_startdate" class="form-control layer-date" onclick="laydate({istime: true, format: 'YYYY-MM-DD  hh:mm:ss'})" ></div>
                            <div class="col-md-2"><input placeholder="结束日期" id="search_enddate" class="form-control layer-date" onclick="laydate({istime: true, format: 'YYYY-MM-DD  hh:mm:ss'})" ></div>
                            <div class="col-md-1"><button id="btn_search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button></div>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-3"> <button style="margin-top: -10px; margin-bottom: -10px;" id="btn_export1" class="btn  btn-success"><i class="fa fa-sign-out"></i>&nbsp;导出Excel</button></div>
                            <div class="col-md-2"><i id="ddze" class="glyphicon glyphicon-usd">订单总额：0.0 </i></div>
                            <div class="col-md-2"><i id="yqze" class="glyphicon glyphicon-list-alt">用券总额：0</i></div>
                            <div class="col-md-2"><i id="fwfze" class="glyphicon glyphicon-credit-card">服务费总额：0.0 </i></div>
                            <div class="col-md-2"><i id="ddbs" class="glyphicon glyphicon-list-alt">订单笔数：0 </i></div>
                        </div>
                    </div>
                </div>
            </div>
            <table id="exampleTablePagination"></table>
        </div>
    </div>
</div>

<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
<script>

</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script type="text/javascript">
    //初始化表格对象
    loadSTKInfo();
    var $table = $('#exampleTablePagination');
    /*
     获取选中行的相关数据
     */
    $(function () {
        $table.on('click-row.bs.table', function (e, row, $element) {
            $('.success').removeClass('success');
            $($element).addClass('success');
        });
        $('#button').click(function () {
            alert('Selected name: ' + getSelectedRow().userName);
        });
    });
    function getSelectedRow() {
        var index = $table.find('tr.success').data('index');
        return $table.bootstrapTable('getData')[index];
    }

    /*
     每一列详情格式化数据
     */
    function formDetail(index, row) {
        return row.detail+index;
    }


    $table.bootstrapTable({
        url: "${pageContext.request.contextPath}/couponUse/queryCouponUseDetail.ac",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",//必须的
        dataType: "json",
        pageList:[10, 20, 50, 100],//会根据当前的数据量加载合适的pageList
        height: ($(window).height()-100) ,
        //cardView:true,//是否自适应手机
        pagination: true, //分页
        // queryParamsType: "limit",
        singleSelect: false,
        cache:false,
        sortName:"createTime",
        search: false, //显示搜索框
        showColumns:false,
        showRefresh:false,
        showToggle:false,
        showPaginationSwitch:false,
        smartDisplay:true,
        detailView:false,
        toolbar:"#toolbar",
        queryParams: queryParams,//参数
        searchOnEnterKey:true,
        sidePagination: "server", //服务端处理分页
        columns: [
            {field:'id', title:'编号', type:'string', align: 'center',visible:false},
            {field:'person_name',title:'领取人', type:'string', align: 'center'},
            {field:'phone',title:'手机号', type:'string', align: 'center'},
            {field:'sourceId',title:'相关编号', type:'string', align: 'center'},
            {field:'brandName',title:'商户名称', type:'string', align: 'center'},
            {field:'shopName',title:'门店名称', type:'string', align: 'center'},
            {field:'sourceMsg',title:'来源', type:'string', align: 'center' },
            {field:'state', title:'订单状态', type:'string', align: 'center',
                formatter:function(value, row, index){
                    if(value == 0){
                        return '未生效';
                    }else if(value == 1){
                        return '交易成功';
                    }else if(value == 2&&row.orderType==2){
                        return '错误';
                    }else if(value == 2&&row.orderType==1){
                        return '已退款';
                    }else if(value == 3&&row.orderType==2){
                        return '已退款';
                    }else if(value == 3&&row.orderType==1){
                        return '错误订单';
                    }
                }
            },
            {field:'point90', title:'用户久零券变化', type:'string', align: 'center',formatter:function(v){
                return (v/100).toFixed(2);
            }},
            {field:'servicePayTotal',title:'服务费', type:'string', align: 'center'},
            {field:'payType', title:'支付方式', type:'string', align: 'center',
                formatter:function(v){
                    if(v == 0){
                        return '余额';
                    }else if(v == 1){
                        return '银联';
                    }else if(v == 2){
                        return '支付宝';
                    }else if(v == 3){
                        return '微支付';
                    }else if(v == 5){
                        return '微信(pay17)';
                    }else if(v == 7){
                        return '线下支付';
                    }
                    else if(v == 'ZFB-MICROPAY'){
                        return '支付宝';
                    }
                    else if(v == 'UNIONPAY'){
                        return '银联';
                    }
                    else if(v == 'offline'){
                        return '线下支付';
                    }
                    else if(v == 'MICROPAY'){
                        return '微支付';
                    }
                }
            },
            {field:'createTime', title:'时间', type:'string', align: 'center'},
            {field:'type', title:'使用途径', type:'string', align: 'center',
                formatter:function(v){
                    if(v == 0){
                        return 'pos机';
                    }else if(v == 1){
                        return 'QT消券';
                    }else if(v == 2){
                        return '微商城';
                    }else if(v == 3){
                        return '远程发券';
                    }else if(v == 4){
                        return '实体卡';
                    }
                }
            }
        ]
    });

    /*
     搜索按钮
     */
    $("#btn_search").click(function(){
        loadSTKInfo();
        $table.bootstrapTable('selectPage', 1);
        $table.bootstrapTable('refresh', queryParams);
    });

    /*
     传递的参数
     */
    function queryParams(params) {
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,  //页面大小
            offset: params.offset, //页码
            pageindex:params.pageNumber,
            code: $("#search_code").val(),
            startDate: $("#search_startdate").val(),
            endDate: $("#search_enddate").val(),
            phone:$("#phone").val()
        };
        return temp;
    }
    ///////////////////////////////////////////////////////////////toolbar///////////////////////////////////////
    //新增
    $("#btn_add").click(function(){
        showPopup();
    });

    //批量删除
    $("#btn_del").click(function(){
        var ids=getSelections();
        //执行批量删除
        deleteGrid(ids);
    });

    /*
     批量删除方法体
     */
    function closeOrder(mainId){
        swal({
            title: "您确定要关闭此订单吗？",
            text: "关闭后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "关闭",
            cancelButtonText:"取消",
            closeOnConfirm: false
        }, function () {
            //执行批量删除
            $.ajax( {
                url:'${pageContext.request.contextPath}/order/closeOrder.ac',
                data:{
                    id :mainId
                },
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    if(data.state == '1'){
                        swal("关闭成功！", "您已经关闭了这个订单。", "success");
                        //当前表格刷新
                        $table.bootstrapTable('refresh');
                    }else{
                        swal("删除失败！", "未能关闭此订单。", "error");
                    }
                },
                error : function() {
                    alert("异常！");
                }
            });

        });
    }

    // 打开订单详情
    function openDetail(id,detailId) {
        window.location.href = "${pageContext.request.contextPath}/order/toDetail.ac?id="
                + id+"&detailId="+detailId;
    }

    //获取选中的CheckBox
    $("#btn_getCheck").click(function(){
        alert('getSelections: ' + JSON.stringify($table.bootstrapTable('getSelections')));
        alert("客户信息:"+$table.bootstrapTable('getSelections')[0].userName);
    });

    function order_excel_deshopMain() {

        var params = {};
        params['startDate'] = $("#search_startdate").val();
        params['endDate'] = $("#search_enddate").val();
        params['personName'] = $("#personName").val();
        var str = encodeURI(encodeURI(JSON.stringify(params)));
        window.location.href = "${pageContext.request.contextPath}/order/exportExcel_shopDeMain.ac?parameters="
                + str;
    }

    function order_excel_deshop() {
        var params = {};
        var params = {};
        params['startdate'] = $("#search_startdate").val();
        params['enddate'] = $("#search_enddate").val();
        params['code'] = $("#search_code").val();
        params['shopId'] = "1283163cd39a4d729a86026c8e601d0c";

        var str = encodeURI(encodeURI(JSON.stringify(params)));

        window.location.href = "${pageContext.request.contextPath}/order/exportExcel_shopDeDetail.ac?parameters="
                + str;
    }
    function  loadSTKInfo(){

        var start= $("#search_startdate").val();
        var end= $("#search_enddate").val();
        $.ajax( {
            url:'${pageContext.request.contextPath}/couponUse/loadTJInfo.ac',// 跳转到 action
            data:{start:start,end:end},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                $("#ddze").html("订单总额："+data.goodsTotal);
                $("#yqze").html("用券总额："+data.payCoupon);
                $("#fwfze").html("服务费总额："+data.servicePayTotal);
                $("#ddbs").html("订单总数："+data.count);
            },
            error : function() {
                alert("加汇总失败！");
            }
        });
    }

    //批量导出
    $("#btn_export1").click(function(){
        var start=$("#search_startdate").val();
        var end=$("#search_enddate").val();
        var phone=$("#phone").val();
        window.location.href="${pageContext.request.contextPath}/couponUse/doExcel.ac?phone="+phone+"&start="+start+"&end="+end;
    });
</script>
</body>


</html>
